package cn.org.xuanguang.kepler.hormos.spring.starter;

import cn.org.xuanguang.kepler.hormos.orm.acl.IPolicyInterceptorChain;
import cn.org.xuanguang.kepler.hormos.orm.dao.DefaultSyncRepository;
import cn.org.xuanguang.kepler.hormos.orm.dao.HormsBaseSyncRepository;
import cn.org.xuanguang.kepler.hormos.rdb.executor.SyncSqlExecutor;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * SyncRepository 实例化类
 *
 * @param <E>
 * @param <PK>
 */
@Getter
@Setter
public class SyncRepositoryFactoryBean<E, PK>
        implements FactoryBean<HormsBaseSyncRepository<E, PK>> {

    @Autowired
    private SyncSqlExecutor syncSqlExecutor;

    //     添加拦截器
    @Autowired
    private IPolicyInterceptorChain policyInterceptorChain;

    private Class<E> entityType;

    @Override
    public HormsBaseSyncRepository<E, PK> getObject() {

        return new DefaultSyncRepository<>(
                syncSqlExecutor,
                entityType,
                policyInterceptorChain);
    }

    @Override
    public Class<?> getObjectType() {
        return HormsBaseSyncRepository.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
